package com.shop.technicalservice.dao.order.impl;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.shop.technicalservice.dao.order.IndentDao;
import com.shop.technicalservice.model.order.Indent;

/**
 * A data access object (DAO) providing persistence and search support for
 * Indent entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see org.rjb.pojo.IndentDto
 * @author MyEclipse Persistence Tools
 */

public class IndentDaoImpl extends HibernateDaoSupport implements IndentDao{
	private static final Log log = LogFactory.getLog(IndentDaoImpl.class);
	// property constants
	public static final String CONSIGNEE = "consignee";
	public static final String ADDRESS = "address";
	public static final String PHONE = "phone";
	public static final String POSTAL_CODE = "postalCode";
	public static final String USER_NAME = "userName";
	public static final String STATUS = "status";

	protected void initDao() {
		// do nothing
	}

	public Indent save(Indent transientInstance)  throws Exception{
		log.debug("saving Indent instance");
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		return transientInstance;
	}

	public void delete(Indent persistentInstance)  throws Exception{
		log.debug("deleting Indent instance");
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
	}

	public Indent findById(java.lang.Integer id)  throws Exception{
		log.debug("getting Indent instance with id: " + id);
			Indent instance = (Indent) getHibernateTemplate().get(
					"org.rjb.Indent", id);
			return instance;
	}

	public List findByExample(Indent instance)  throws Exception{
		log.debug("finding Indent instance by example");
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
	}

	public List findByProperty(String propertyName, Object value)  throws Exception{
		log.debug("finding Indent instance with property: " + propertyName
				+ ", value: " + value);
			String queryString = "from Indent as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
	}

	public List findByConsignee(Object consignee)  throws Exception{
		return findByProperty(CONSIGNEE, consignee);
	}

	public List findByAddress(Object address) throws Exception {
		return findByProperty(ADDRESS, address);
	}

	public List findByPhone(Object phone) throws Exception {
		return findByProperty(PHONE, phone);
	}

	public List findByPostalCode(Object postalCode)  throws Exception{
		return findByProperty(POSTAL_CODE, postalCode);
	}

	public List findByUserName(Object userName) throws Exception {
		return findByProperty(USER_NAME, userName);
	}

	public List findByStatus(Object status)  throws Exception{
		return findByProperty(STATUS, status);
	}

	public List findAll()  throws Exception{
		log.debug("finding all Indent instances");
			String queryString = "from Indent";
			return getHibernateTemplate().find(queryString);
	}

	public Indent merge(Indent detachedInstance)  throws Exception{
		log.debug("merging Indent instance");
			Indent result = (Indent) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
	}

	public void attachDirty(Indent instance)  throws Exception{
		log.debug("attaching dirty Indent instance");
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
	}

	public void attachClean(Indent instance)  throws Exception{
		log.debug("attaching clean Indent instance");
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
	}

	 
}